package com.zeldu.course.controller;

import com.zeldu.course.pojo.Course;
import com.zeldu.course.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @RequestMapping(value = "queryStudentAll",method = {RequestMethod.GET})
    @ResponseBody
    public List<Course> queryStudentAll(Long studentId){
        return courseService.queryStudentAll(studentId);
    }

    @RequestMapping(value = "detail",method = {RequestMethod.GET})
    @ResponseBody
    public Course detail(int id){
        return courseService.detail(id);
    }

    @RequestMapping(value = "join",method = {RequestMethod.POST})
    @ResponseBody
    public int join(@RequestBody Course course){
        int x = courseService.available(course.getId());
        if(x==0) return -1;
        int y = courseService.exist(course);
        if(y!=0) return 0;
        return courseService.join(course);
    }

    @RequestMapping(value = "queryTeacherAll",method = {RequestMethod.GET})
    @ResponseBody
    public List<Course> queryTeacherAll(Long teacherId){
        return courseService.queryTeacherAll(teacherId);
    }

    @RequestMapping(value = "showClass",method = {RequestMethod.GET})
    @ResponseBody
    public List<Course> showClass(Long teacherId){
        return courseService.showClass(teacherId);
    }

    @RequestMapping(value = "create",method = {RequestMethod.POST})
    @ResponseBody
    public int create(@RequestBody Course course){
        return courseService.create(course);
    }

    @RequestMapping("queryStudentsId")
    @ResponseBody
    public List<Course> queryStudentsId(int courseId){
        return courseService.queryStudentsId(courseId);
    }
}
